import Vue from 'vue'
// 存储localStorage时设置前缀
const storePrefix = 'PIE_';

// 存储localStorage
export const setStore = (name, content) => {
	if (!name) return;
	if (typeof content !== 'string') {
		content = JSON.stringify(content);
	}
	window.localStorage.setItem(storePrefix + name, content);
}

// 获取localStorage
export const getStore = name => {
	if (!name) return;
	return JSON.parse(window.localStorage.getItem(storePrefix + name));
}

// 删除localStorage
export const removeStore = name => {
	if (!name) return;
	window.localStorage.removeItem(storePrefix + name);
}

//获取日期20171221格式
export const seriDate=(_time)=>{
		var s=new Date(_time);
		var y=s.getFullYear();
		var m=s.getMonth()+1;
		var d=s.getDate();
		return ''+y+(m>=10?m:'0'+m)+(d>=10?d:'0'+d)
	}

//匹配出科目名称或id
export const subjectMatch=(ele)=>{
	var arr=[
					{name:'数学',courseid:'13'},
					{name:'语文',courseid:'12'},
					{name:'物理',courseid:'15'},
					{name:'化学',courseid:'16'},
					{name:'生物',courseid:'17'},
					{name:'政治',courseid:'11'},
					{name:'历史',courseid:'18'},
					{name:'地理',courseid:'19'},
					{name:'英语',courseid:'14'}
				]
	
	if(!parseInt(ele)){
		if(arr.find(function(x){return x.name==ele})){		
		return arr.find(function(x){return x.name==ele}).courseid
	}else{
		return 'not find'
	}
	}else{
		if(arr.find(function(x){return x.courseid==ele})){		
		return arr.find(function(x){return x.courseid==ele}).name
	}else{
		return 'not find'
	}
	}	
}
export const bus = new Vue({})
